home *** CD-ROM | disk | FTP | other *** search
Text File | 1987-03-22 | 2.9 KB | 120 lines | [TEXT/MPS ] |
- program drag;
-
- USES {$LOAD pinterfaces.dump}
- MemTypes,QuickDraw,OsIntf,PasLibIntf,ToolIntf,
- PackIntf,IntEnv,CursorCtl;
-
- var myPic : PicHandle;
- myRect : Rect;
- oldPort: GrafPtr;
-
- procedure DragIt( thePicture : PicHandle );
- var
- underBits, pictureBits : BitMap;
- where : Point;
- thePictureRgn : RgnHandle;
- wMgrPort,
- oldPort,
- workPort : GrafPtr;
- dragRect,
- tempBounds : Rect;
- mousePt, testPt : Point;
- synchCount : longint;
- begin
- {remember where we are}
- GetPort( oldPort );
- GetWMgrPort( wMgrPort );
-
- {try to allocate and erase the bitmaps}
- tempBounds := thePicture^^.picFrame;
- with underBits, tempBounds do
- begin
- rowBytes := ((right - left + 15) DIV 16) * 2;
- baseAddr := NewPtr(rowBytes * (bottom - top));
- bounds := tempBounds;
- if MemError <> noErr then
- baseAddr := nil;
- if baseAddr = nil then IEExit(1);
- end;
- with pictureBits, tempBounds do
- begin
- rowBytes := ((right - left + 15) DIV 16) * 2;
- baseAddr := NewPtr(rowBytes * (bottom - top));
- bounds := tempBounds;
- if MemError <> noErr then
- baseAddr := nil;
- if baseAddr = nil then IEExit(1);
- end;
-
- workPort := GrafPtr( NewPtr( sizeof(GrafPort) ) );
- if workPort = nil then IEExit(1);
-
- OpenPort( workPort );
- SetPortBits( underBits );
- EraseRect( underBits.bounds );
- SetPortBits( pictureBits );
- EraseRect( pictureBits.bounds );
-
- {draw the picture into pictureBits & create thePictureRgn}
- thePictureRgn := NewRgn;
- OpenRgn;
- DrawPicture( thePicture, thePicture^^.picFrame );
- CloseRgn( thePictureRgn );
- DrawPicture( thePicture, thePicture^^.picFrame );
-
- {these are the rectangles for use in CopyBits}
- dragRect := pictureBits.bounds;
-
- SetPort( wMgrPort );
- while button do
- begin
- GetMouse( mousePt );
- OffSetRgn( thePictureRgn, -dragRect.left, -dragRect.top );
- OffSetRgn( thePictureRgn, mousePt.h, mousePt.v );
- OffSetRect( dragRect, -dragRect.left, -dragRect.top );
- OffSetRect( dragRect, mousePt.h, mousePt.v );
-
- {save bits underneath}
- CopyBits( screenBits, underBits, dragRect, underBits.bounds,
- srcCopy,nil);
- {mask out shape of my object}
- CopyBits( pictureBits, screenBits, pictureBits.bounds, dragRect,
- notSrcBic, thePictureRgn );
- {draw my object}
- CopyBits( pictureBits, screenBits, pictureBits.bounds, dragRect,
- srcOr, thePictureRgn );
- repeat
- GetMouse( testPt );
- until not EqualPt( testPt, mousePt );
-
- synchCount := TickCount;
- repeat until TickCount <> synchCount;
- {restore bits underneath}
- CopyBits( underBits, screenBits, underBits.bounds, dragRect,
- srcCopy, nil);
- end; {while button}
-
- {tidy up}
- SetPort( oldPort );
- ClosePort( workPort );
- DisposPtr( Pointer(workPort) );
- DisposPtr( pictureBits.baseAddr );
- DisposPtr( underBits.baseAddr );
- DisposHandle( Handle(thePictureRgn) );
-
- end; {DragIt}
-
- begin{main}
- InitGraf(@thePort);
- GetWMgrPort( oldPort );
- SetPort( oldPort );
-
- ClipRect( screenBits.bounds );
- myPic := PicHandle(GetResource('PICT', 128));
-
- InitCursor;
- repeat until button;
- DragIt( myPic );
- IEExit(0);
- end.
-